package com.web;

import java.io.IOException;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.domain.Goods;
import com.service.Impl.GoodsServiceImpl;

@WebServlet("/indexServlet")
public class indexServlet extends HttpServlet{
	private GoodsServiceImpl goodsService = new GoodsServiceImpl();
	
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //查询人气商品
        List<Goods> Hot = goodsService.findHot();
        List<Goods> Hot2 = goodsService.findHot2();

        //查询最新商品
        List<Goods> New = goodsService.findNew();
        List<Goods> New2 = goodsService.findNew2();


        //将数据存储到域对象中
        request.setAttribute("Hot", Hot);
        request.setAttribute("Hot2", Hot2);
        request.setAttribute("New", New);
        request.setAttribute("New2", New2);

        //取出Session域中存的用户名
        HttpSession session = request.getSession();
        String username = (String) session.getAttribute("username");
        request.setAttribute("massge", "欢迎~ "+username);
        //转发到page中的index.jsp
        request.getRequestDispatcher("/page/index.jsp").forward(request, response);
    }
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		this.doGet(req, resp);
	}
}
